import { PartialType } from '@nestjs/mapped-types';
import { Transform } from 'class-transformer';
import { IsIdentityCard, IsNotEmpty, IsMobilePhone } from 'class-validator';

export class OrderDto {
  @IsNotEmpty({ message: '乘车人姓名不能为空' })
  passenger: string;

  @IsNotEmpty({ message: '身份证号不能为空' })
  @IsIdentityCard('zh-CN', { message: '身份证号格式不正确' })
  identityNumber: string;

  @IsNotEmpty({ message: '手机号不能为空' })
  @IsMobilePhone('zh-CN', {}, { message: '手机号格式不正确' })
  mobile: string;

  @IsNotEmpty({ message: '车次号不能为空' })
  trainNo: string;

  @IsNotEmpty({ message: '车厢号不能为空' })
  coachNo: string;

  @IsNotEmpty({ message: '座位号不能为空' })
  seatNo: string;

  @IsNotEmpty({ message: '座位等级不能为空' })
  seatLevel: string;

  @IsNotEmpty({ message: '出发站号不能为空' })
  fromStationNo: string;

  @IsNotEmpty({ message: '出发站名不能为空' })
  fromStationName: string;

  @IsNotEmpty({ message: '到达站不能为空' })
  toStationNo: string;

  @IsNotEmpty({ message: '到达站名不能为空' })
  toStationName: string;

  @IsNotEmpty({ message: '乘车日期不能为空' })
  departureTime: string;

  @IsNotEmpty({ message: '到达日期不能为空' })
  arrivalTime: string;

  @IsNotEmpty({ message: '票价不能为空' })
  price: number;
}

export class QueryOrderPage extends PartialType(OrderDto) {
  @IsNotEmpty({ message: '页码不能为空' })
  @Transform(({ value }) => Number(value))
  current: number;

  @IsNotEmpty({ message: '每页数量不能为空' })
  @Transform(({ value }) => Number(value))
  size: number;
}
